# > Logic only. Program this as if it were multiplayer.
# That's why we don't need to import OS or JSON
# Because we won't be loading any of our own data,
# Right?

import math

def get_nature_multiplier(nature,stat):
	if stat==nature['dec']:return 0.9
	elif stat==nature['inc']:return 1.1
	else:return 1

def calculate_stat(pokemon,species,nature,stat_name):
	stat_name=stat_name.lower()
	#I haven't dumped the ev values yet, I don't think.
	#ret=pokemon['iv'][stat_name]+(2*species['stats'][stat_name])+(species['ev'][stat_name]/4)
	#use v- this -v for the time being, instead. ( it's a minimal effect anyways. )
	ret=pokemon['iv'][stat_name]+(2*species['stats'][stat_name])
	if stat_name=='hp':ret=floor((ret+100)*pokemon['level']/100)+10
	else:ret=floor(((ret*pokemon['level']/100)+5)*get_nature_multiplier(nature,stat_name))
	return ret

class StatSet:
	def __init__(self,p,s,n):
		self.vals=dict([(stat_name,{'val':calculate_stat(p,s,n,stat_name),'level':1}) for stat_name in s['stats'].keys()])

	def adjust_level(self,s,l):	
		if l in [a for a in self.levels.keys()]:self.vals[s]['level']+=l

	def __getitem__(self,stat):return floor(self.vals[stat]['val']*self.levels[self.vals[stat]['level']])

class TurnDelegate: #This is more accurate, I believe. Battle should be a task, should it not?
    def __init__(self):
        self.trainers = []
        self.teams = {}
 
    def join(self, trainer, tname):
        assert self.complies_with_rules(trainer)
        assert trainer not in self.trainers # No double-joining
        self.trainers.append(trainer)
        self.teams[trainer] = tname
 
    def turn_of(self):
        return self.trainers[0]
 
    def rotate(self):
        self.trainers.append(self.trainers.pop(0))
 
    def complies_with_rules(self, trainer):
        return True
 
    def flee(self, stack):
        raise NotImplementedError()
